package com.sc.collection.job;


import com.sc.collection.entity.City;
import com.sc.collection.feign.FeignService;
import com.sc.collection.service.WeatherDataCollectionService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

/**
 * @author shuchang
 * @Date 2018/3/16 下午3:09
 */
@Slf4j
public class WeatherSyncJob extends QuartzJobBean {

    @Autowired
    private WeatherDataCollectionService weatherDataService;
    @Autowired
    private FeignService feignService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        log.info("定时作业");
        List<City> listCity = feignService.listCity();
        listCity.forEach(i -> weatherDataService.syncDataByCityId(i.getCityId()));
        log.info("定时任务结束");
    }
}
